

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>AG_fft_tools.psds &mdash; agpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="../../_static/extra.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="agpy 0.1.2 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" />
     
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setDomainName', 'pyspeckit.bitbucket.org']);
      _gaq.push(['_setAllowHash', false]);
      _gaq.push(['_trackPageview']);


    </script>
    <link rel="stylesheet" type="text/css" href="../../_static/extra.css" />
  </head>
  <body>
    <div class="header-wrapper">
      <div class="header">
        <h1><a href="../../index.html">agpy 0.1.2 documentation</a></h1>
        <div class="rel">
          <a href="http://agpy.googlecode.com">agpy Home </a>  |
          <a href=../../index.html>Docs Home </a>  |
          <a href="http://code.google.com/p/agpy/w/list">Wiki</a>  |
          <a href=../../search.html>Search </a>
        </div>
       </div>
    </div>

    <div class="content-wrapper">
      <div class="content">
        <div class="document">
            
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for AG_fft_tools.psds</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Power Spectra</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">numpy</span>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">pyplot</span>
    <span class="n">pyplotOK</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="n">pyplotOK</span> <span class="o">=</span> <span class="bp">False</span>
<span class="kn">from</span> <span class="nn">correlate2d</span> <span class="kn">import</span> <span class="n">correlate2d</span>
<span class="kn">from</span> <span class="nn">AG_image_tools.radialprofile</span> <span class="kn">import</span> <span class="n">azimuthalAverageBins</span><span class="p">,</span><span class="n">radialAverageBins</span>

<div class="viewcode-block" id="hanning2d"><a class="viewcode-back" href="../../fft_tools.html#AG_fft_tools.psds.hanning2d">[docs]</a><span class="k">def</span> <span class="nf">hanning2d</span><span class="p">(</span><span class="n">M</span><span class="p">,</span> <span class="n">N</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A 2D hanning window, as per IDL&#39;s hanning function.  See numpy.hanning for the 1d description</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="n">N</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">hanning</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">M</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">hanning</span><span class="p">(</span><span class="n">N</span><span class="p">)</span> <span class="c"># scalar unity; don&#39;t window if dims are too small</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">hanning</span><span class="p">(</span><span class="n">M</span><span class="p">),</span><span class="n">numpy</span><span class="o">.</span><span class="n">hanning</span><span class="p">(</span><span class="n">N</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="power_spectrum"><a class="viewcode-back" href="../../fft_tools.html#AG_fft_tools.psds.power_spectrum">[docs]</a><span class="k">def</span> <span class="nf">power_spectrum</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Thin wrapper of PSD2.  Returns the 1D power spectrum in stead of the 2D Power Spectral Density</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;oned&#39;</span><span class="p">]</span><span class="o">=</span><span class="bp">True</span>
    <span class="k">return</span> <span class="n">PSD2</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="PSD2"><a class="viewcode-back" href="../../fft_tools.html#AG_fft_tools.psds.PSD2">[docs]</a><span class="k">def</span> <span class="nf">PSD2</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">image2</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">oned</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> 
        <span class="n">fft_pad</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">imag</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
        <span class="n">binsize</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">radbins</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">azbins</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">radial</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">hanning</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> 
        <span class="n">wavnum_scale</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">twopi_scale</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Two-dimensional Power Spectral Density.</span>
<span class="sd">    NAN values are treated as zero.</span>

<span class="sd">    image2 - can specify a second image if you want to see the cross-power-spectrum instead of the </span>
<span class="sd">        power spectrum.</span>
<span class="sd">    oned - return radial profile of 2D PSD (i.e. mean power as a function of spatial frequency)</span>
<span class="sd">           freq,zz = PSD2(image); plot(freq,zz) is a power spectrum</span>
<span class="sd">    fft_pad - Add zeros to the edge of the image before FFTing for a speed</span>
<span class="sd">        boost?  (the edge padding will be removed afterwards)</span>
<span class="sd">    real - Only compute the real part of the PSD (Default is absolute value)</span>
<span class="sd">    imag - Only compute the complex part of the PSD (Default is absolute value)</span>
<span class="sd">    hanning - Multiply the image to be PSD&#39;d by a 2D Hanning window before performing the FTs.  </span>
<span class="sd">        Reduces edge effects.  This idea courtesy Paul Ricchiazzia (May 1993), author of the</span>
<span class="sd">        IDL astrolib psd.pro</span>
<span class="sd">    wavnum_scale - multiply the FFT^2 by the wavenumber when computing the PSD?</span>
<span class="sd">    twopi_scale - multiply the FFT^2 by 2pi?</span>
<span class="sd">    azbins - Number of azimuthal (angular) bins to include.  Default is 1, or</span>
<span class="sd">        all 360 degrees.  If azbins&gt;1, the data will be split into [azbins]</span>
<span class="sd">        equally sized pie pieces.  Azbins can also be a numpy array.  See</span>
<span class="sd">        AG_image_tools.azimuthalAverageBins for details</span>
<span class="sd">        </span>
<span class="sd">    </span>
<span class="sd">    radial - An option to return the *azimuthal* power spectrum (i.e., the spectral power as a function </span>
<span class="sd">        of angle).  Not commonly used.</span>
<span class="sd">    radbins - number of radial bins (you can compute the azimuthal power spectrum in different annuli)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="c"># prevent modification of input image (i.e., the next two lines of active code)</span>
    <span class="n">image</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

    <span class="c"># remove NANs (but not inf&#39;s)</span>
    <span class="n">image</span><span class="p">[</span><span class="n">image</span><span class="o">!=</span><span class="n">image</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="k">if</span> <span class="n">hanning</span><span class="p">:</span>
        <span class="n">image</span> <span class="o">=</span> <span class="n">hanning2d</span><span class="p">(</span><span class="o">*</span><span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">*</span> <span class="n">image</span>

    <span class="k">if</span> <span class="n">image2</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">image2</span> <span class="o">=</span> <span class="n">image</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">image2</span> <span class="o">=</span> <span class="n">image2</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">image2</span><span class="p">[</span><span class="n">image2</span><span class="o">!=</span><span class="n">image2</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="n">hanning</span><span class="p">:</span>
            <span class="n">image2</span> <span class="o">=</span> <span class="n">hanning2d</span><span class="p">(</span><span class="o">*</span><span class="n">image2</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">*</span> <span class="n">image2</span>

    <span class="k">if</span> <span class="n">real</span><span class="p">:</span>
        <span class="n">psd2</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">real</span><span class="p">(</span> <span class="n">correlate2d</span><span class="p">(</span><span class="n">image</span><span class="p">,</span><span class="n">image2</span><span class="p">,</span><span class="n">return_fft</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">fft_pad</span><span class="o">=</span><span class="n">fft_pad</span><span class="p">)</span> <span class="p">)</span> 
    <span class="k">elif</span> <span class="n">imag</span><span class="p">:</span>
        <span class="n">psd2</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">imag</span><span class="p">(</span> <span class="n">correlate2d</span><span class="p">(</span><span class="n">image</span><span class="p">,</span><span class="n">image2</span><span class="p">,</span><span class="n">return_fft</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">fft_pad</span><span class="o">=</span><span class="n">fft_pad</span><span class="p">)</span> <span class="p">)</span> 
    <span class="k">else</span><span class="p">:</span> <span class="c"># default is absolute value</span>
        <span class="n">psd2</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span> <span class="n">correlate2d</span><span class="p">(</span><span class="n">image</span><span class="p">,</span><span class="n">image2</span><span class="p">,</span><span class="n">return_fft</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">fft_pad</span><span class="o">=</span><span class="n">fft_pad</span><span class="p">)</span> <span class="p">)</span> 
    <span class="c"># normalization is approximately (numpy.abs(image).sum()*numpy.abs(image2).sum())</span>

    <span class="k">if</span> <span class="n">wavnum_scale</span><span class="p">:</span>
        <span class="n">wx</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">dtype</span><span class="o">=</span><span class="s">&#39;float&#39;</span><span class="p">)</span> <span class="p">,</span> <span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span> <span class="o">-</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">dtype</span><span class="o">=</span><span class="s">&#39;float&#39;</span><span class="p">)</span> <span class="o">-</span><span class="mi">1</span> <span class="p">])</span> <span class="o">/</span> <span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="mf">2.</span><span class="p">)</span>
        <span class="n">wy</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">dtype</span><span class="o">=</span><span class="s">&#39;float&#39;</span><span class="p">)</span> <span class="p">,</span> <span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span> <span class="o">-</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">dtype</span><span class="o">=</span><span class="s">&#39;float&#39;</span><span class="p">)</span> <span class="o">-</span><span class="mi">1</span> <span class="p">])</span> <span class="o">/</span> <span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mf">2.</span><span class="p">)</span>
        <span class="n">wx</span><span class="o">/=</span><span class="n">wx</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
        <span class="n">wy</span><span class="o">/=</span><span class="n">wy</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
        <span class="n">wavnum</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span> <span class="n">numpy</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">wx</span><span class="p">,</span><span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">shape</span><span class="p">))</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">numpy</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">wy</span><span class="o">.</span><span class="n">shape</span><span class="p">),</span><span class="n">wx</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="p">)</span>
        <span class="n">psd2</span> <span class="o">*=</span> <span class="n">wavnum</span>

    <span class="k">if</span> <span class="n">twopi_scale</span><span class="p">:</span>
        <span class="n">psd2</span> <span class="o">*=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">2</span>

    <span class="k">if</span> <span class="n">radial</span><span class="p">:</span>
        <span class="n">azbins</span><span class="p">,</span><span class="n">az</span><span class="p">,</span><span class="n">zz</span> <span class="o">=</span> <span class="n">radialAverageBins</span><span class="p">(</span><span class="n">psd2</span><span class="p">,</span><span class="n">radbins</span><span class="o">=</span><span class="n">radbins</span><span class="p">,</span> <span class="n">interpnan</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">binsize</span><span class="o">=</span><span class="n">binsize</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">zz</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">az</span><span class="p">,</span><span class="n">zz</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">az</span><span class="p">,</span><span class="n">zz</span>

    <span class="k">if</span> <span class="n">oned</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">pspec</span><span class="p">(</span><span class="n">psd2</span><span class="p">,</span> <span class="n">azbins</span><span class="o">=</span><span class="n">azbins</span><span class="p">,</span> <span class="n">binsize</span><span class="o">=</span><span class="n">binsize</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="c"># else...</span>
    <span class="k">return</span> <span class="n">psd2</span>
</div>
<div class="viewcode-block" id="pspec"><a class="viewcode-back" href="../../fft_tools.html#AG_fft_tools.psds.pspec">[docs]</a><span class="k">def</span> <span class="nf">pspec</span><span class="p">(</span><span class="n">psd2</span><span class="p">,</span> <span class="n">return_index</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">wavenumber</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">return_stddev</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">azbins</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">binsize</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">view</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Create a Power Spectrum (radial profile of a PSD) from a Power Spectral Density image</span>

<span class="sd">    return_index - if true, the first return item will be the indexes</span>
<span class="sd">    wavenumber - if one dimensional and return_index set, will return a normalized wavenumber instead</span>
<span class="sd">    view - Plot the PSD (in logspace)?</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c">#freq = 1 + numpy.arange( numpy.floor( numpy.sqrt((image.shape[0]/2)**2+(image.shape[1]/2)**2) ) ) </span>

    <span class="n">azbins</span><span class="p">,(</span><span class="n">freq</span><span class="p">,</span><span class="n">zz</span><span class="p">)</span> <span class="o">=</span> <span class="n">azimuthalAverageBins</span><span class="p">(</span><span class="n">psd2</span><span class="p">,</span><span class="n">azbins</span><span class="o">=</span><span class="n">azbins</span><span class="p">,</span><span class="n">interpnan</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">binsize</span><span class="o">=</span><span class="n">binsize</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">zz</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="n">zz</span><span class="o">=</span><span class="n">zz</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="c"># the &quot;Frequency&quot; is the spatial frequency f = 1/x for the standard numpy fft, which follows the convention</span>
    <span class="c"># A_k =  \sum_{m=0}^{n-1} a_m \exp\left\{-2\pi i{mk \over n}\right\}</span>
    <span class="c"># or </span>
    <span class="c"># F_f = Sum( a_m e^(-2 pi i f x_m)  over the range m,m_max where a_m are the values of the pixels, x_m are the</span>
    <span class="c"># indices of the pixels, and f is the spatial frequency</span>
    <span class="n">freq</span> <span class="o">=</span> <span class="n">freq</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s">&#39;float&#39;</span><span class="p">)</span>  <span class="c"># there was a +1.0 here before, presumably to deal with div-by-0, but that shouldn&#39;t happen and shouldn&#39;t have been &quot;accounted for&quot; anyway</span>

    <span class="k">if</span> <span class="n">return_index</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">wavenumber</span><span class="p">:</span>
            <span class="n">return_vals</span> <span class="o">=</span> <span class="nb">list</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">freq</span><span class="p">)</span><span class="o">/</span><span class="n">freq</span><span class="p">,</span><span class="n">zz</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">return_vals</span> <span class="o">=</span> <span class="nb">list</span><span class="p">((</span><span class="n">freq</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">freq</span><span class="p">),</span><span class="n">zz</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">return_vals</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">zz</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">return_stddev</span><span class="p">:</span>
        <span class="n">zzstd</span> <span class="o">=</span> <span class="n">azimuthalAverageBins</span><span class="p">(</span><span class="n">psd2</span><span class="p">,</span><span class="n">azbins</span><span class="o">=</span><span class="n">azbins</span><span class="p">,</span><span class="n">stddev</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">interpnan</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">binsize</span><span class="o">=</span><span class="n">binsize</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">return_vals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">zzstd</span><span class="p">)</span>
    
    <span class="k">if</span> <span class="n">view</span> <span class="ow">and</span> <span class="n">pyplotOK</span><span class="p">:</span>
        <span class="n">pyplot</span><span class="o">.</span><span class="n">loglog</span><span class="p">(</span><span class="n">freq</span><span class="p">,</span><span class="n">zz</span><span class="p">)</span>
        <span class="n">pyplot</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s">&quot;Spatial Frequency&quot;</span><span class="p">)</span>
        <span class="n">pyplot</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s">&quot;Spectral Power&quot;</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">return_vals</span></div>
</pre></div>

          </div>
        </div>
      </div>
        </div>
        <div class="sidebar">
          <h3>Table Of Contents</h3>
          <ul>
<li class="toctree-l1"><a class="reference internal" href="../../agpy.html">Adam Ginsburg&#8217;s Python Code (agpy)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../image_tools.html">Image Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fft_tools.html">AG_fft_tools Package</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../plfit.html">plfit Package</a></li>
</ul>

          <h3 style="margin-top: 1.5em;">Search</h3>
          <form class="search" action="../../search.html" method="get">
            <input type="text" name="q" />
            <input type="submit" value="Go" />
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>
          <p class="searchtip" style="font-size: 90%">
            Enter search terms or a module, class or function name.
          </p>
        </div>
        <div class="clearer"></div>
      </div>
    </div>

    <div class="footer">
      &copy; Copyright 2011, Adam Ginsburg.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2pre.
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-6253248-2']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
        
    </div>
  </body>
</html>